Keeping Buttons in a Pressed State

Description

By default, the buttons that you add to a UX component only remain in their 'pressed' state for as long as you hold down the mouse-button over them. As soon as the mouse-button is released the button will return to its regular unpressed state. Sometimes, however, it is useful to keep a button in its pressed state until something, like a dialog, is closed or some action is run.

Setting the State on a Normal Button

There is currently no easy way to set a pressed state on a normal button. Work is being done to remedy this. To be updated....

Pressed State on Split Buttons

Split buttons are covered more extensively in the '[Split Buttons]' guide. The section below describes how you can set split buttons to have a 'pressed' or 'not pressed' state.

  1. In the UX Builder, on the UX Controls page, open the 'Other Controls' menu. Click on the [Button] option to add a button control to the component.

    images/ps2.png
  2. Highlight the button in the controls tree. In the Properties list on the right, the 'Advanced button control type' property in the 'Button Properties' section should be set to 'Button'.

    images/ps3.png
  3. In the 'Button Appearance' section check the 'Has dropdown icon' checkbox.

    images/ps4.png
  4. Check the 'Display as split button' checkbox that appears.

    images/ps5.png
  5. Go to the 'Other Controls' menu on left and click on the [Button] option again to add a second button to the component.

    images/ps2.png
  6. Highlight the second button in the controls tree. In the Properties list on the right set the 'Button text' to read 'Pressed'.

    images/ps6.png
  7. Scroll down to the 'Javascript' section and click the [...] button next to the 'onClick' property.

    images/ps7.png
  8. Select the 'Text mode' radio button option in the 'Editing mode' menu, add the following code to the onClick event's definition, and click Save.

    var b = {dialog.object}.getControl('BUTTON_1');
    b.setState({dialog.object}.getPointer('BUTTON_1'),true);
    images/ps8.png
  9. In the Other Controls menu click on [Button] a third time to add another button to the component.

    images/ps9.png
  10. Highlight the third button in the controls tree and, in the Properties list, set the 'Button text' property to read 'Not Pressed'.

    images/ps10.png
  11. Scroll down to the 'Javascript' section for the third button and click the [...] button next to the 'onClick' property.

    images/ps11.png
  12. In the 'Edit onClick Event' dialog select the 'Text mode' radio button option and add the following code to the onClick event's definition. Click Save.

    var b = {dialog.object}.getControl('BUTTON_1');
    b.setState({dialog.object}.getPointer('BUTTON_1'),false);
    images/ps12.png
  13. Run the component in 'Live Preview'. When you click on the 'Pressed' button the split button should stay in its pressed state.

    images/ps13.png
  14. Press the 'Not Pressed' button. The split button should return to normal.

    images/ps14.png

See Also